<?php

class ErrorController extends ControllerBase
{

    public function errorAction()
    {
        $errors = $this->_getParam('error_handler');
        
        if (!$errors || !$errors instanceof ArrayObject) {
            $this->view->message = 'You have reached the error page';
            return;
        }
        
        switch ($errors->type) {
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
           $this->getResponse ()->setHttpResponseCode ( 404 );
				$priority = Zend_Log::NOTICE;
				
				$this->view->title = '{Show title here ...}';
				$this->view->message = <<<EOS
                    <div>
                       {Show error message here ...}
                    <div>
                    {$backToTop}
EOS;
				$this->_logger->debug ( $errors->exception );
				$this->_logger->debug ( 'Request Parameters : ' . var_export ( $errors->request->getParams (), true ) );
				break;
			default :
				// application error
				$this->getResponse ()->setHttpResponseCode ( 500 );
				$priority = Zend_Log::CRIT;
				$this->view->title = 'An unexpected error has occurred';
				$this->view->message = <<<EOS
                    <div>
                       The server has detected an error and not able to run. <br />
                       Please visit again or put some time, please contact the administrator.
                    <div>
                    {$backToTop}
EOS;
				
				$this->_logger->err ( $errors->exception );
				$this->_logger->err ( 'Request Parameters : ' . var_export ( $errors->request->getParams (), true ) );
				break;
        }
        
       $this->view->errors = $errors;
    }

    public function getLog()
    {
        $bootstrap = $this->getInvokeArg('bootstrap');
        if (!$bootstrap->hasResource('Log')) {
            return false;
        }
        $log = $bootstrap->getResource('Log');
        return $log;
    }


}

